<?php
   class ApiCenter_SalesApi_Model_Api2_Orderdata_Rest extends ApiCenter_SalesApi_Model_Api2_Orderdata{
    
       
       //获取商家所有的主订单列表
       protected  function _getOrderForCollection($vendorId){
           
           $collection = Mage::getResourceModel('sales/order_item_collection');
           $collection->addFieldToFilter("main_table.vendor_id",$vendorId);
           $collection->addFieldToFilter("main_table.parent_item_id",array('null' => ''));
           $collection->addFieldToFilter("d.status","payment_success");
           $collection->addFieldToSelect("sku");
           $collection->getSelect()
           ->join(array('d' => 'sales_flat_order'),
               'd.entity_id = main_table.order_id',
               array(
                   "increment_id"=>"d.increment_id",
                   "order_id"=>"d.entity_id",
                   "created_at"=>"d.created_at"
               ));
            
           return $collection;
       }
       
       
       //获取商家所有的主订单列表
       protected  function _getPrdouctForCollection($vendorId,$filter=NUll){
            
           $collection = Mage::getModel('catalog/product')->getCollection();
           
           $collection->addFieldToFilter("vendor_id",$vendorId);
           
           if($filter){
               foreach ($filter as $filterEntry) {
                   $attributeCode = $filterEntry['attribute'];
                   unset($filterEntry['attribute']);
                   $collection->addFieldToFilter($attributeCode, $filterEntry);
               }
           }
           return $collection;
       }
       //加载已分订单信息
       
       /**
        * @return collection
        * */
       protected function _loadChildOrder($pid,$vendorId,$filter=null){
           /** @var $collection ApiCenter_SalesApi_Model_Resource_Mysql4_Order_Collection */
           $collection = Mage::getResourceModel('salesapi/order_collection');
           $collection->addFieldToFilter("main_table.vendor_id",$vendorId);
           $collection->addFieldToFilter("main_table.increment_id",array("like"=>$pid."%"));
           if($filter){
               foreach ($filter as $filterEntry) {
                   $attributeCode = $filterEntry['attribute'];
                   unset($filterEntry['attribute']);
                   $collection->addFieldToFilter($attributeCode, $filterEntry);
               }
           }
           return $collection;
       }
       
     
  }